package com.dfbz.bigdata.modules.system.miniapp.controller;


import com.dfbz.bigdata.common.utils.R;
import com.dfbz.bigdata.modules.system.miniapp.domain.WXAuth;
import com.dfbz.bigdata.modules.system.miniapp.dto.UserDto;
import com.dfbz.bigdata.modules.system.miniapp.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("miniLogin")
@Slf4j
public class LoginController {

    @Autowired
    private UserService userService;


    @GetMapping("/getSessionId")
    public R<Map> getSessionId(@RequestParam String code) {

        log.info("code  {}",code);
        String sessionId = userService.getSessionId(code);
        HashMap<String, String> hashMap = new HashMap<>();
        hashMap.put("sessionId", sessionId);
        System.out.println(hashMap);
        return R.success(hashMap);
    }

    @PostMapping("/authLogin")
    public R<UserDto> authLogin(@RequestBody WXAuth wxAuth) {

        log.info("wxAuth-----{}",wxAuth);

        R<UserDto> userDtoR = userService.authLogin(wxAuth);

        return userDtoR;
    }
}
